package LeetCode;

public class LC_667_BeautifulArrangementII {

    public static void main(String[] args) {

    }

    class Solution {
        public int[] constructArray(int n, int k) {
            int[] res = new int[n];
            int max = n, min = 1;
            int i;
            for (i = 0; i < k; i++) {
                if (i % 2 != 0) res[i] = max--;
                else res[i] = min++;
            }
            if (i % 2 == 0) {
                for (int j = k; j < n; j++)
                    res[j] = max--;
            } else {
                for (int j = k; j < n; j++)
                    res[j] = min++;
            }
            return res;
        }
    }

}